// pages/studyDetail/studyDetail.js
Page({
  data: {
    globalData: getApp().globalData,
    article: {},
    zan: '',
    customerFlag: true
  },

  onLoad(options) {
    let {id} = options
    this.getArticle(id)
  },

  getArticle(id) {
    let that = this
    wx.request({
      url: this.data.globalData.server + '/article/' + id,
      method: 'GET',
      success(res) {
        that.setData({
          article: res.data.data
        })
      },
      complete() {
        that.read()
      }
    })
  },
  // 点赞
  like() {
    let that = this
    wx.request({
      url: this.data.globalData.server + '/article',
      data: {
        articleId: this.data.article.articleId,
        articleZan: this.data.article.articleZan + 1
      },
      method: 'PUT',
      success(res) {
        that.setData({
          zan: 'red'
        })
      }
    })
  },
  // 阅读量
  read() {
    wx.request({
      url: this.data.globalData.server + '/article',
      data: {
        articleId: this.data.article.articleId,
        articleRead: this.data.article.articleRead + 1
      },
      method: 'PUT',
    })
  },
  // 客服
  showCustomer() {
    this.setData({
      customerFlag: false
    })
  },
  closeCustomer() {
    this.setData({
      customerFlag: true
    })
  }
  
})